/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 var mergeNodes = function(head) {
  const arr = []
  let cur = head
  while(cur){
    arr.push(cur.val)
    cur = cur.next
  }
  const dummy = new ListNode(-1), c = dummy
  let sum = 0
  for(let x of arr) {
    if(x === 0 && sum !== 0) {
      c.next = new ListNode(sum)
      sum = 0
      c = c.next
    }
    sum += x
  }
  return dummy.next
};